<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>找回密码</title>
    <link rel="shortcut icon" href="./images/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/base-ui.css">
    <link rel="stylesheet" href="./css/message.css">
    <script src="./js/jquery-3.4.1.min.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            width: 100%;
            height: 100vh;
        }

        main {
            height: 100%;
            width: 100%;
            display: flex;
            font-family: MiSans,sans-serif;
        }

        .account-body {
            width: 100%;
            background-color: var(--color-background-soft);
            position: relative;
        }

        .account-card {
            width: 400px;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            background-color: var(--color-background);
            border-radius: 5px;
            box-shadow: var(--shadow2);
            overflow: hidden;
            padding: 20px;
        }

        .account-card .title {
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .account-card .title a {
            color: var(--ui-colors-neutral10);
        }

        .account-card .title a:hover {
            color: var(--ui-colors-orange);
        }

        .account-card .account-content {
            width: 100%;
            display: flex;
            column-gap: 20px;
            overflow: hidden;
            transition: all 0.35s ease-in-out;
        }

        .account-input {
            width: 100%;
            font-family: 'Segoe UI', sans-serif;
            margin: 1em 0 1em 0;
            position: relative;
            background-color: var(--ui-colors-neutral2);
        }

        .account-input input {
            font-size: 100%;
            padding: 0.8em;
            outline: none;
            border: 2px solid var(--color-none);
            background-color: transparent;
            border-radius: 5px;
            width: 100%;
        }

        .account-input label {
            font-size: 100%;
            position: absolute;
            left: 0;
            padding: 0.8em;
            margin-left: 0.5em;
            pointer-events: none;
            transition: all 0.3s ease;
            color: var(--ui-colors-neutral10);
            font-weight: 500;
        }

        .account-input :is(input:focus, input:valid)~label {
            transform: translateY(-50%) scale(.9);
            margin: 0em;
            margin-left: 1.3em;
            padding: 0.4em;
        }

        .account-input :is(input:focus, input:valid) {
            border-color: var(--ui-colors-orange);
        }

        .block {
            display: none;
            height: 4px;
            width: 60px;
            background-color: var(--color-background);
            position: absolute;
            top: -1px;
            left: 20px;
            transition: all 0.35s ease-in-out;
        }
        .account-input :is(input:focus, input:valid) ~ .block {
            display: inline;
        }

        .account-content .bottom {
            width: 100%;
        }

        .account-content .bottom button {
            width: 100%;
            height: 60px;
            background-color: var(--ui-colors-orange);
            border-radius: 3px;
            font-size: 20px;
            font-weight: 600;
            color: var(--color-background);
        }

        .result-content {
            margin: 30px 0;
            background-color: var(--ui-colors-info4);
            border: 1px solid var(--ui-colors-info6);
            color: var(--ui-colors-info9);
            border-radius: 3px;
            line-height: 1.25;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .result-content span {
            margin: 10px 0;
        }
        
    </style>
</head>
<body>
    <main>
        <div class="account-body">
            <div class="account-card">
                <div class="title">
                    <h2>找回密码</h2>
                    <a href="/account#login">回到登录</a>
                </div>
                <div class="account-content" style="background: var(--color-none);">
                    <div style = "width: 100%;" id="input-info">
                        <form class="" style="width: 100%;">
                            <div>
                                <div class="account-input">
                                    <input type="text" name="username" id="username" 
                                    class="form-control" required="required" title="">
                                    <div class="block"></div>
                                    <label for="username">
                                        用户名
                                    </label>
                                </div>
                            </div>
                            <div>
                                <div class="account-input">
                                    <input type="text" name="telephone" id="telephone" 
                                    class="form-control" required="required" title="">
                                    <div class="block" style="width: 77px;"></div>
                                    <label for="telephone">
                                        电话号码
                                    </label>
                                </div>
                            </div>
                        </form>
                        <div class="bottom">
                            <button onclick="getPwd()">确认</button>
                        </div>
                    </div>
                    <div style = "width: 100%; display: none;" id="result">
                        <div class="result-content">
                            <span id="result-text"></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>
</body>
<script src="./js/message.js"></script>
<script>
    function getPwd() {
        let username=$("#username").val()
        let tel=$("#telephone").val()
        let namereg=/^[\u4e00-\u9fa5]{0,}$/;
        let telreg=/(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
        if( namereg.test(username) && telreg.test(tel) ){//验证数据是否符合要求
            $.ajax({//使用ajax发送用户数据，进行注册验证
                url:"/api/forget",
                method:"post",
                data:{
                    username:username,
                    tel:tel
                },
                success(res){
                    if(res.code != 1001){
                        AddMessage("warning", "用户名或号码有误")
                    } else {
                        document.getElementById("input-info").style.display = "none"
                        document.getElementById("result").style.display = "inline"
                        document.getElementById("result-text").innerText = res.pwd
                    }
                }
            })
        } else {
            AddMessage("warning", "数据格式不合法")
        }
    }
</script>
</html>